import * as React from "react"
import { observable } from "mobx"
import { observer, inject } from "mobx-react"
import FN from "../tools/fn"

import { Router, Switch, Redirect, withRouter, Link,Route} from 'react-router-dom'
import { hashHistory } from 'react-router';
import CacheRoute, { CacheSwitch } from 'react-router-cache-route'
import ErrorBoundary from "../../components/errorBoundary"

@inject("RouteQ")
@observer
export default class ChildrenRouter extends React.Component {
  constructor(props) {
    super(props)
    this.store = this.props.RouteQ.Maps;//通过mobx来获取路由配置
    console.log("this.props.RouteQ.Maps",this.props.RouteQ.Maps)
  }
  render() {
      console.log(this.props.match)
      console.log("this.store===",this.store)
    return (
        <ErrorBoundary>
            <CacheSwitch>
                    <Redirect exact from="/cacheRoute" to="/cacheRoute/list" />
                    {this.store.map((route, i) =>{
                        if(route.cache){
                            return <CacheRoute when="always" strict key={i} {...route}/>
                        }
                        else{
                            return <Route strict key={i} {...route}/>
                        }
                    }})} 
            </CacheSwitch>  
        </ErrorBoundary>      
    )
  } 
}


